package models

import (
	"gorm.io/gorm"
	"zk2/common/mysql"
)

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(30);not null;comment:用户名"`
	Password string `gorm:"type:varchar(20);not null;comment:密码"`
	Mobile   string `gorm:"type:char(11);not null;comment:手机号"`
}

func (u *User) Reg() error {
	return mysql.Db.Model(User{}).Create(&u).Error
}

func Login(mobile string) (u *User, err error) {
	err = mysql.Db.Model(User{}).Where("mobile = ?", mobile).First(&u).Error
	return
}
